package com.dapeis.fromt.controller;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.dapeis.core.utils.StylistConstants;
import com.dapeis.domain.Company;
import com.dapeis.service.CompanyService;

@Controller
@RequestMapping(value = "/")
public class HomeController{
	@Resource
	CompanyService companyService;
	@RequestMapping
	public String index(HttpSession session, RedirectAttributes attr){
		return "/index";
	}
	
	@RequestMapping(value="/joinUs",method=RequestMethod.POST)
	public String join(@RequestParam Integer job ,@RequestParam String name,@RequestParam String wechat,
			@RequestParam String contact,@RequestParam String cityName ,@RequestParam(required = false) String brand 
			,@RequestParam(required = false) String storeName ,@RequestParam(required = false) String storeAddress,
			 Map<Object,Object> model, HttpSession session){
		Company company = new Company();
		company.setName(name);
		company.setContact(contact);
		company.setWechat(wechat);
		company.setCityName(cityName);
		if(job == StylistConstants.Job.DESIGNER){
			company.setBrand(brand);
		}else if(job == StylistConstants.Job.SHOPS){
			company.setBrand(brand);
			company.setStoreAddress(storeAddress);
			company.setStoreName(storeName);
		}
		companyService.insertSelective(company);
		return null;
	}
}
